<?php

/**
 * @author 
 * @copyright 2008
 */
/** Остаток пути. который используется в качестве списка входных данных **/
$over = $this->fetchPath($this->path);
$show="index";
if(!empty($over))
{
	if(preg_match("/^cat_(\w+)$/",$over[0],$searched_category))
	{
		$show="category";
		$item_alias = $searched_category[1];
	}
	elseif(preg_match("/^(\w+)$/",$over[0],$searched_item))
	{
		$show="item";
		$item_alias = $searched_item[1];
	}
}
$table_catalog=PFX."video_catalog";
$per_page=5;
$lim_from=$from*$per_page;
if($show=="index")
{
	/** FILTER **/
	if(isset($_POST['filter_off']))
	{
		unset($_SESSION['filter']);
		unset($_POST['filter_off']);
	}
	elseif(isset($_POST['filter_on']))
	{
		$filter=$_POST['filter'];
		$_SESSION['filter']=$filter;
		$_SESSION['filter']['status']='on';
		unset($_POST['filter']);
	}
	elseif(isset($_SESSION['filter']))
	{
		$filter=$_SESSION['filter'];
	}
	$sql_clause=array();
	$sql_where='';
	if(isset($filter))
	{
		if($filter['factory']!='0')
			$sql_clause[]= "$table.factory_id='".$filter['factory']."'";
		if($filter['style']!='0')
			$sql_clause[]= "$table.style_id='".$filter['style']."'";
		if($filter['type']!='0')
			$sql_clause[]= "$table.type_id='".$filter['type']."'";
		if(!empty($sql_clause))
			$sql_where="AND ".implode(' AND ',$sql_clause);
	}
	/** END FILTER **/
	// выборка необходимых товаров
	$items=$db->fetch_array("SELECT SQL_CALC_FOUND_ROWS $table_catalog.* FROM $table_catalog WHERE $table_catalog.status>'0' $sql_where ORDER BY time DESC LIMIT $lim_from,$per_page");
	if($items!=false)
	{
		foreach($items as $k=>$v)
		{
		}
		$quantity = $db->fetch_one(QUANTITY);
		if($quantity[0]>0)
		{
			$smarty->assign("kolvo",$quantity[0]);
			$smarty->assign("items",$items);
			if($quantity[0]>$per_page)
			{
				$per_page_navigation = ceil($quantity[0]/$per_page);
				$smarty->assign("ppn",$per_page_navigation);
			}
		}
	}
}
elseif($show=="filter")
{
	
}
elseif($show=="item")
{
	$item=$db->fetch_one("SELECT $table_catalog.* FROM $table_catalog WHERE $table_catalog.alias='".$item_alias."' AND $table_catalog.status>'0'");
	if($item!=false)
	{
		if($item['image']=='1')
		{
			$sizes=@getimagesize(ROOT_DIR.UPLOAD.$page['dir']."/".$item['id']."_small.jpg");
			if($sizes!=false)
			{
				$item['photo']=UPLOAD.$page['dir']."/".$item['id'];
			}
			else $item['photo']=false;
		}
		else $item['photo']=false;
		$smarty->assign("item",$item);
		$page['template']="item";
	}
	$this->template = "item";
}

?>